<style>
.app-main{
  background: #f5f9ff;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
<template>
  <div class="app-container" style="margin: auto; margin-top: 20px; border-radius:5px; width: 80%;  background: #FFFFFF">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-button plain>导入</el-button>
      <el-button @click="handleExport" plain>导出</el-button>
      <el-button plain @click="dayin">打印</el-button><br>
      <el-form-item label="回单状态" prop="returnStatus">
        <el-select v-model="queryParams.returnStatus" placeholder="回单状态" clearable>
          <el-option value="" label="全部"></el-option>
          <el-option value="已回收" label="已回收"></el-option>
          <el-option value="未回收" label="未回收"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus" >
        <el-select v-model="queryParams.orderStatus" clearable placeholder="订单状态">
          <el-option value="" label="全部"></el-option>
          <el-option value="已签收" label="已签收"></el-option>
          <el-option value="未签收" label="未签收"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发货时间" clearable>
        <el-date-picker
          clearable
          v-model="daterangeShippingTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="签收时间" clearable>-->
<!--        <el-date-picker-->
<!--          clearable-->
<!--          v-model="daterangeDate"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="silpList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="${comment}" align="center" prop="id" />-->
      <el-table-column label="订单号" align="center" prop="orderNumber" width="120">
        <template slot-scope="scope">
          <el-link @click="handleUpdate(scope.row)" type="primary">{{scope.row.orderNumber}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="客户" align="center" prop="customer" width="120"/>
      <el-table-column label="回单状态" align="center" prop="returnStatus" width="120"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="120"/>
      <el-table-column label="回单份数" align="center" prop="returnCopies" width="120"/>
      <el-table-column label="发货地址" align="center" prop="shippingAddress" width="120"/>
      <el-table-column label="发货时间" align="center" prop="shippingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shippingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收货地址" align="center" prop="receivingAddress" />
      <el-table-column label="签收数量" align="center" prop="signedQuantity" />
      <el-table-column label="签收人" align="center" prop="signedBy" />
      <el-table-column label="签收时间" align="center" prop="signedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--&lt;!&ndash;          <el-button&ndash;&gt;-->
<!--&lt;!&ndash;            size="mini"&ndash;&gt;-->
<!--&lt;!&ndash;            type="text"&ndash;&gt;-->
<!--&lt;!&ndash;            icon="el-icon-view"&ndash;&gt;-->
<!--&lt;!&ndash;            v-hasPermi="['silp:silp:query']"&ndash;&gt;-->
<!--&lt;!&ndash;            @click="handleView(scope.row,scope.index)"&ndash;&gt;-->
<!--&lt;!&ndash;          >上传回单</el-button>&ndash;&gt;-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改回单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="客户" prop="customer">
          <el-input v-model="form.customer" placeholder="请输入客户" />
        </el-form-item>
        <el-form-item label="回单份数" prop="returnCopies">
          <el-input v-model="form.returnCopies" placeholder="请输入回单份数" />
        </el-form-item>
        <el-form-item label="发货地址" prop="shippingAddress">
          <el-input v-model="form.shippingAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发货时间" prop="shippingTime">
          <el-date-picker clearable
            v-model="form.shippingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货地址" prop="receivingAddress">
          <el-input v-model="form.receivingAddress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="签收数量" prop="signedQuantity">
          <el-input v-model="form.signedQuantity" placeholder="请输入签收数量" />
        </el-form-item>
        <el-form-item label="签收人" prop="signedBy">
          <el-input v-model="form.signedBy" placeholder="请输入签收人" />
        </el-form-item>
        <el-form-item label="签收时间" prop="signedTime">
          <el-date-picker clearable
            v-model="form.signedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择签收时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="上传回单"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="快递公司" prop="departure">
        <el-select v-model="queryParams.departure" placeholder="快递公司">
          <el-option label="京东" value="京东"></el-option>
          <el-option label="顺丰" value="顺丰"></el-option>
          <el-option label="韵达" value="韵达"></el-option>
          <el-option label="申通" value="申通"></el-option>
        </el-select>
      </el-form-item>
        <el-form-item label="邮寄单号" prop="number">
          <el-input v-model="queryParams.number" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="寄件日期" prop="number">
          <el-date-picker
            v-model="value1"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上传回单" prop="number">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

  </div>
</template>

<script>
import { listSilp, getSilp, delSilp, addSilp, updateSilp } from "@/api/silp/silp";

export default {
  name: "Silp",
  data() {
    return {
      daterangeShippingTime:[],
      imageUrl:"",
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 回单表格数据
      silpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        returnStatus: null,
        orderStatus: null,
        shippingTime: null,
        signedTime: null
      },
      handleView(){
        this.dialogVisible = true
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNumber: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        customer: [
          { required: true, message: "客户不能为空", trigger: "blur" }
        ],
        returnStatus: [
          { required: true, message: "回单状态不能为空", trigger: "change" }
        ],
        orderStatus: [
          { required: true, message: "订单状态不能为空", trigger: "change" }
        ],
        returnCopies: [
          { required: true, message: "回单份数不能为空", trigger: "blur" }
        ],
        shippingAddress: [
          { required: true, message: "发货地址不能为空", trigger: "blur" }
        ],
        shippingTime: [
          { required: true, message: "发货时间不能为空", trigger: "blur" }
        ],
        receivingAddress: [
          { required: true, message: "收货地址不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    if(this.$route.query.returnStatus != null && this.$route.query.returnStatus != undefined){
      this.queryParams.returnStatus = this.$route.query.returnStatus;
      this.getList();
    }
    this.getList();
  },
  methods: {
    dayin(){
      window.print();
    },
    /** 查询回单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeShippingTime && '' != this.daterangeShippingTime) {
        this.queryParams.params["beginShippingTime"] = this.daterangeShippingTime[0];
        this.queryParams.params["endShippingTime"] = this.daterangeShippingTime[1];
      }
      listSilp(this.queryParams).then(response => {
        this.silpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        customer: null,
        returnStatus: null,
        orderStatus: null,
        returnCopies: null,
        shippingAddress: null,
        shippingTime: null,
        receivingAddress: null,
        signedQuantity: null,
        signedBy: null,
        signedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加回单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      this.$router.push({path:'/operation/operationXq',query:{id:id}})
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSilp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSilp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除回单编号为"' + ids + '"的数据项？').then(function() {
        return delSilp(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('silp/silp/export', {
        ...this.queryParams
      }, `silp_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
